$(function () {

    $(".maillast").on("click",function () {
        $("<ul><li>@163.com</li><li>@126.com</li><li>@yeah.net</li></ul>").appendTo($(this));
        $(this).find("li").on("mouseenter",function () {
            $(this).css({"background":"dodgerblue","color":"white"}).siblings().css({"background":"white","color":"dimgray"});
        })
        $(this).find("li").on("click",function (evt) {
            $(".maillast").text($(this).text());
            $(".maillast").find("ul").remove();
            evt.stopPropagation();
        })
    })
    //用正则判断账号密码手机号
    var flag = true;
   var  arrJudge = ["帐号须由6-18个字符组成，尝试注册当前帐号？","密码须由6-16个字符组成，区分大小写","密码不一致","请点击验证码","请输入正确的手机号"];
    var regArr = [reg=/^[a-zA-Z0-9]+@+[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/,reg=/^\w{6,18}/,"","",reg=/^(135|137|138|178)\d{8}/];
    var flag = [false,false,"","",false]
    $(".textinput input").on("blur",function () {
        var temp = $(this).parent().index();
        if (temp < 5 && temp != 3 && temp != 2) {
            var Judge = $(this).siblings(".judge")
                Judge.html("")
                if (regArr[temp].test($(this).val())) {
                    $("<i id='true'></i>").appendTo(Judge)
                    flag[temp]=true
                } else {
                    $("<i></i><span>" + arrJudge[temp] + "</span>").appendTo(Judge)
                    flag[temp]=false
                    moveagain(Judge)
            }
        }
    })
    //判断密码是否相同
    $(".textinput input").eq(2).on("blur",function () {
        var Judge1 = $(this).siblings(".judge")
        Judge1.html("")
        console.log($(this).val());
        console.log($(".textinput input").eq(1).val());
        if($(this).val()==$(".textinput input").eq(1).val()){
            $("<i id='true'></i>").appendTo(Judge1)
        }else {
            $("<i></i><span>" + arrJudge[2] + "</span>").appendTo(Judge1)
            moveagain(Judge1)
        }
    })


    function moveagain(Judge) {
        if (flag == true) {
            flag = false
            Judge.animate({"left": "670px"}, 50, function () {
                Judge.animate({"left": "675px"}, 50, function () {
                    Judge.animate({"left": "670px"}, 50, function () {
                        Judge.animate({"left": "675px"}, 50, function () {
                            flag = true;
                        })
                    })
                })
            })
        }
    }


    $("#zcyh").on("click",function(){
        var arr = $.toObject($("#myinfo").serialize())
        var adss = arr.umail.replace(/%40/,"@")
        arr.umail=adss;

        $.ajax({
            type:"post",
            url:"http://localhost/project/register.php",
            async:true,
            data:arr,
            success:function(res){
                console.log(res)
                 var ser = JSON.parse(res)
                if(ser.status==1){
                    setTimeout(function(){
                        window.location.href = "../index.html"
                    },100)
                }
            }
        });

    })
})
